import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jetour_line/my_colors.dart';
import 'package:jetour_line/utils/aha_utils.dart';
import 'package:jetour_line/utils/extension_int.dart';

import 'base_image.dart';

class SelBtnWidget extends StatefulWidget {
  final String title;
  final List<String> msg;
  final Function callBack;
  int selIndex;

  SelBtnWidget(
      {super.key,
      required this.title,
      required this.msg,
      this.selIndex = -1,
      required this.callBack});

  @override
  State<SelBtnWidget> createState() => _SelBtnWidgetState();
}

class _SelBtnWidgetState extends State<SelBtnWidget> {
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Container(
            alignment: Alignment.centerLeft,
            width: double.infinity,
            color: Colors.white,
            height: 96.px,
            child: Row(

              children: [
                SizedBox(width: 32.px,),
                Expanded(
                  child: Text(
                    widget.title,
                    style: TextStyle(
                        fontSize: 32.px,
                        color: MyColors.color1A1A1A,
                        fontWeight: FontWeight.w500),
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    Navigator.pop(context);
                  },
                  child: ClipRRect(
                    borderRadius:
                    BorderRadius.all(Radius.circular(20.px)),
                    child: Opacity(
                      opacity: 0.8,
                      child: Container(
                        alignment: Alignment.center,
                        color: MyColors.color26282D,
                        width: 40.px,
                        height: 40.px,
                        child: BaseImage(
                          image: 'lsgj_btn_closewh',
                          width: 20.px,
                          height: 20.px,
                        ),
                      ),
                    ),
                  ),
                ),
                SizedBox(width: 32.px,),
              ],
            )),
        Container(
          padding: EdgeInsets.all(32.px),
          color: Colors.white,
          width: double.infinity,
          child: Wrap(
            alignment: WrapAlignment.start,
            runAlignment: WrapAlignment.center,
            spacing: 11.px,
            runSpacing: 11.px,
            children: [
              for (int i = 0; i < widget.msg.length; i++)
                GestureDetector(
                  onTap: () {
                    widget.callBack(i);
                    Navigator.pop(context);
                  },
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(4.px)),
                    child: Container(
                      alignment: Alignment.center,
                      color: widget.selIndex == i
                          ? MyColors.color00A198
                          : MyColors.colorF1F1F1,
                      width: (AhaUtils.getScreenWidth(context) - 98.px) / 3,
                      height: 70.px,
                      child: Text(
                        widget.msg[i],
                        style: TextStyle(
                            fontSize: 30.px,
                            color: widget.selIndex == i
                                ? MyColors.white
                                : MyColors.color333333),
                      ),
                    ),
                  ),
                )
            ],
          ),
        )
      ],
    );
  }
}
